package com.neusoft.neuiotms.dcom.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.ResidentChangeLogDTO;
import com.neusoft.neuiotms.dcom.dto.ResidentUserDTO;
import com.neusoft.neuiotms.dcom.model.ResidentChangeLog;

@Component
public class ResidentChangeLogConverter extends AbstractConverter<ResidentChangeLog, ResidentChangeLogDTO> {

    @Override
    public ResidentChangeLog toModel(final ResidentChangeLogDTO dto) {
        return null;
    }

    @Override
    public ResidentChangeLogDTO toDTO(final ResidentChangeLog model, final boolean forListView) {

        final ResidentChangeLogDTO dto = new ResidentChangeLogDTO();
        dto.setId(model.getId());
        dto.setInstitution(model.getInstitutions().getId());
        dto.setChangeAt(model.getChangeAt());

        final List<ResidentUserDTO> residents = new ArrayList<>();
        model.getResidents().forEach(it -> {
            final ResidentUserDTO d = new ResidentUserDTO();
            d.setUsername(it.getUsername());
            d.setName(it.getName());
            residents.add(d);
        });
        dto.setResidents(residents);

        return dto;
    }

}
